﻿using UnityEngine;

public class ActionTile {
	// === Public =====================================================================================================
	public static void CreateOrChangeObjectUsingTile() {
		var transObjModel = MapEditorBaseData.GetInstance.TransparentObject.ElementModel;
		var transObjPos = new Vector2(transObjModel.Position.x, transObjModel.Position.z);
		foreach (var editorElement in Game.GetGameModel().Elements) {
			if (!transObjPos.x.Equals(editorElement.ElementModel.Position.x) ||
				!transObjPos.y.Equals(editorElement.ElementModel.Position.z) ||
				!ElementType.Tile.Equals(editorElement.ElementModel.ElementType)) {
				continue;
			}
			editorElement.SetTexture(transObjModel.TexturePath);
			return;
		}
		var element = Creators.Element.Create(new PropertyElementTile(transObjPos, transObjModel.TexturePath));
		Game.GetGameModel().AddElement(element);
	}
}
